package com.zsn.demo.service.impl;

import com.zsn.demo.service.AsyncService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.concurrent.CountDownLatch;

/**
 * @author zhushuainan
 * @title: AsyncServiceImpl
 * @projectName excelDemo
 * @description: TODO
 * @date 2022/11/9 10:22
 */
@Component
public class AsyncServiceImpl implements AsyncService {


    @Override
    @Async("asyncServiceExecutor")
    public void writeTxt(CountDownLatch countDownLatch,int i, ArrayList<Object> errorList) {
        try {
            if (i%2 == 0){
                 i=i/0;
            }
            System.out.println(i+ new Date().toString());
        } catch (Exception e) {
            errorList.add(i);
        } finally {
            countDownLatch.countDown();
        }
//        try {
//            Thread.sleep(3000);
//        } catch (InterruptedException e) {
////            Thread.currentThread().interrupt();
//        }
    }
}
